package solutions.leetcode.normal;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/minimum-sideway-jumps/">1824. 最少侧跳次数</a>
 */
public class Solution1824 extends BaseSolution {

    public int minSideJumps(int[] obstacles) {
        int[] tmp = new int[3];
        tmp[0] = 1;
        tmp[2] = 1;
        for (int i = 1; i < obstacles.length; i++) {
            int n1 = obstacles[i] == 1 ? Integer.MAX_VALUE : tmp[0];
            int n2 = obstacles[i] == 2 ? Integer.MAX_VALUE : tmp[1];
            int n3 = obstacles[i] == 3 ? Integer.MAX_VALUE : tmp[2];
            int t1 = obstacles[i] == 1 ? -1 : tmp[0] == -1 ? Math.min(n2, n3) + 1 : tmp[0];
            int t2 = obstacles[i] == 2 ? -1 : tmp[1] == -1 ? Math.min(n1, n3) + 1 : tmp[1];
            int t3 = obstacles[i] == 3 ? -1 : tmp[2] == -1 ? Math.min(n1, n2) + 1 : tmp[2];
            tmp[0] = t1;
            tmp[1] = t2;
            tmp[2] = t3;
        }
        return Math.min(tmp[0], Math.min(tmp[1], tmp[2]));
    }

    public static void main(String[] args) {
        Solution1824 solution = new Solution1824();
        System.out.println(solution.minSideJumps(new int[] {
                0,2,1,0,3,0
        }));
    }
}